<template>
  <div class="container" style="padding-top: 0">
    <van-cell-group class="my-info">
      <van-cell class="base-info" center :border="false">
        <van-image class="avatar" slot="icon" round fit="cover" :src="userInfo.avatar" />
        <div class="name" slot="title">{{userInfo.nickname}}</div>
        <van-button class="update-btn" size="small" round to="/my-list">编辑资料</van-button>
      </van-cell>


      <van-grid class="data-info" :border="false" :column-num="2">
        <van-grid-item class="data-info-item">
          <div slot="text" class="text-wrap" @click="$router.push('/myplush')">
            <div class="count">{{publish_num}}</div>
            <div class="text">头条</div>
          </div>
        </van-grid-item>
        <van-grid-item class="data-info-item">
          <div class="text-wrap" slot="text">
            <div class="count">{{liked_num}}</div>
            <div class="text">获赞</div>
          </div>
        </van-grid-item>
      </van-grid>
    </van-cell-group>

    <van-grid class="nav-grid mb-4" :column-num="2">
      <van-grid-item class="nav-grid-item" @click="$router.push('/likepush')">
        <span class="iconfont">
          <van-icon name="star-o" color="red" />
        </span>
        <span>收藏</span>
      </van-grid-item>
      <van-grid-item class="nav-grid-item" @click="$router.push('/wtachlit')">
        <span class="iconfont">
          <van-icon name="clock-o" color="#fff81e" />
        </span>
        <span>历史</span>
      </van-grid-item>
    </van-grid>
    <van-cell title="修改密码" is-link to="/pasXl" />
    <van-cell title="忘记密码" is-link to="/getPass" />
    <van-cell title="联系我们" is-link to="/" />
    <van-cell class="mb-4" title="关于我们" is-link to="/" />
    <van-cell class="logout-cell" title="退出登录" @click="logout()" />

    <!-- <div class="not-login" style="display: none">
      <div>
        <img class="mobile" src="" />
      </div>
      <div class="text">登录 / 注册</div>
    </div> -->
  </div>
</template>

<script>
import { Dialog } from "vant";
export default {
  name: "App03My",
  components: {
    [Dialog.name]: Dialog
  },
  data() {
    return {
      userInfo:{},
      publish_num:'',
      liked_num:''
    };
  },

  mounted() {
    this.getUserInfo()
   },

  methods: {
    // 退出登录
    logout() {
      this.$dialog
        .confirm({
          title: "提示",
          message: "您确定要退出当前账号吗?",
        })
        .then((res) => {
          console.log(res)
          localStorage.removeItem("xl-token");
          localStorage.removeItem("xl-tokenExpired");
          localStorage.removeItem("xl-uid");
          localStorage.removeItem("xl-userInfo");

          setTimeout(() => {
            this.$router.push('/login')
          }, 1000)
        })
        .catch((err) => {
          console.log(err);
        });
    },
    // 获取用户信息
    getUserInfo() {
      let token = localStorage.getItem("xl-token"); //
      if (!token) {
        setTimeout(() => {
          this.$router.back();
        }, 800);
        this.$toast("参数错误");
        return;
      }
      this.$axios
        .post("/user/getuserInfo", {
          token: token,
        })
        .then((res) => {
          console.log(res);
          if (res.code == 0) {
            this.userInfo = res.userInfo;
            this.publish_num = res.publish_num
            this.liked_num = res.liked_num
          } else {
            this.$toast(res.msg);
          }

          //  console.log(res)
        });
    },
  },
};
</script>

<style lang="scss" scoped>
.container {
  .my-info {
    background: url("~@/assets/banner.jpg") no-repeat;
    background-size: cover;
    height: 47.333333vw;

    .base-info {
      box-sizing: border-box;
      height: 115px;
      background-color: unset;
      padding-top: 38px;
      padding-bottom: 11px;

      .avatar {
        box-sizing: border-box;
        width: 66px;
        height: 66px;
        border: 1px solid #fff;
        margin-right: 11px;
      }

      .name {
        font-size: 15px;
        color: #fff;
      }

      .update-btn {
        height: 24px;
        font-size: 12px;
        color: #666666;
      }
    }

    .data-info {

      // background-color: none;
      .data-info-item {
        // background-color: none !important;
        height: 65px;
        color: #fff;

        .text-wrap {
          display: flex;
          flex-direction: column;
          justify-content: center;
          align-items: center;

          .count {
            font-size: 18px;
          }

          .text {
            font-size: 11px;
          }
        }
      }
    }

    .van-grid-item__content {
      background-color: unset;
    }
  }

  .not-login {
    height: 180px;
    background: url("~@/assets/banner.jpg") no-repeat;
    background-size: cover;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;

    .mobile {
      width: 66px;
      height: 66px;
    }

    .text {
      font-size: 14px;
      color: #fff;
    }
  }

  .nav-grid {
    .nav-grid-item {
      height: 70px;

      .iconfont {
        font-size: 22px;
        margin-bottom: 5px;
      }

      .icon-shoucang {
        color: #eb5253;
      }

      .icon-lishi {
        color: #ff9d1d;
      }

      .van-grid-item__text {
        font-size: 14px;
        color: #333333;
      }
    }
  }

  .logout-cell {
    text-align: center;
    color: #d86262;
  }

  .mb-4 {
    margin-bottom: 4px;
  }
}
</style>
